package com.pi.pro.xcmg.am.was.edi.infor.service;





import com.pi.common.utils.StringUtils;
import com.pi.common.utils.TextUtils;
import com.pi.config.InforWmsClientSecretConfig;
import com.pi.pro.xcmg.am.common.XcmgAmConstants;
import com.pi.pro.xcmg.am.was.edi.infor.common.InforWasExchangeSupport;
import com.pi.pro.xcmg.am.was.edi.infor.dto.reply.FuncReplyData;
import com.pi.pro.xcmg.am.was.edi.infor.dto.reply.TaskReportResultDto;
import com.pi.pro.xcmg.am.was.edi.infor.dto.req.FuncRequestData;
import com.pi.pro.xcmg.am.was.edi.infor.dto.req.TaskReportData;
import com.pi.wms.fac.conn.HttpAccessUrl;
import com.pi.wms.fac.conn.HttpConstants;
import com.pi.wms.fac.conn.HttpclientProxy;
import lombok.Getter;
import lombok.Setter;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.HashMap;
import java.util.Map;


/**
 */
@Getter
@Setter
public class TaskServiceProxy extends BaseInforExchangeServiceProxy {

    private HttpclientProxy wmsTaskClient;
    private HttpAccessUrl wmsTaskReportPostAccessUrl;

    @Autowired
    private InforWmsClientSecretConfig secretConfig;

    //
    public FuncReplyData<TaskReportResultDto> report(FuncRequestData<TaskReportData> reports) {
        FuncReplyData<TaskReportResultDto> replyData=null;
        String replyText = "";
        if (this.wmsTaskClient==null){
            return InforWasExchangeSupport.errorReply("install client error");
        }
        Map<String,String> headers = new HashMap<>();
        try{
            headers.put("Content-Type", XcmgAmConstants.HTTP_CONTENT_TYPE_HTTP_JSON);
            headers.put("sectionId", StringUtils.ifNullOrBlank(this.sectionId, secretConfig.getAppcode()));
            headers.put("token", StringUtils.ifNullOrBlank(this.token, secretConfig.getToken()));

            replyText = this.wmsTaskClient.post(this.wmsTaskReportPostAccessUrl, null, headers,
                    HttpConstants.URL_METHOD_POST, TextUtils.toJsonText(reports));

            //TODO:HU/
            //202505
            System.out.println("#####################XWMS-TASKREPORT-REPLY:"+replyText);

            replyData= InforWasExchangeSupport.trimParseJson(replyText, TaskReportResultDto.class);
        }catch (Exception e){
            e.printStackTrace();
            replyText="send task report error.//"+e.getMessage();
            replyData= InforWasExchangeSupport.errorReply(replyText);
        }
        return replyData;
    }
}
